package com.berchen.utils;

import com.berchen.common.result.ResultEnum;
import com.berchen.exception.ZdyException;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class DateTimeUtils {
    private DateTimeUtils(){}

    public static void main(String[] args){

    }

    /**
     * 获取day月的最后一天
     * @param day
     * @return
     */
    public static String getLastDayOfMonth(LocalDate day){

        return new SimpleDateFormat("yyyy-MM-dd").format(Date.from(day.with(TemporalAdjusters.lastDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    }

    /**
     * 获取day月的第一天
     * @param day
     * @return
     */
    public static String getFirstDayOfMonth(LocalDate day){

        return  new SimpleDateFormat("yyyy-MM-dd").format(Date.from(day.with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    }
}
